<template>
	<!-- 物资管理列表 -->
	<view>
		<view class="page">
			<view class="example-body">
				<uni-nav-bar background-color="#003466" color="#ffffff" :status-bar="true" @click-left="back" left-icon="arrowleft" style="position: relative;">
					<view class="flex-item">维护任务详情</view>
				</uni-nav-bar>
			</view>
			<view class="manintenance-container">
				<view class="maninterance-words" v-show="systemFlag">
					<view class="maninterance-words-left">所属系统</view>
					<view class="maninterance-words-right">{{ systemName }}</view>
				</view>
				<view class="maninterance-words">
					<view class="maninterance-words-left">处理对象</view>
					<view class="maninterance-words-right">{{ detail.equipmentRowGuid }}</view>
				</view>
				<view class="maninterance-words">
					<view class="maninterance-words-left">任务分类</view>
					<view class="maninterance-words-right">{{ detail.category }}</view>
				</view>
				<view class="maninterance-words">
					<view class="maninterance-words-left">任务优先级</view>
					<view class="maninterance-words-right">{{ detail.priorityLevel }}</view>
				</view>
				<view class="maninterance-words">
					<view class="maninterance-words-left">任务状态</view>
					<view class="maninterance-words-right">{{ detail.status }}</view>
				</view>
				<view class="maninterance-words">
					<view class="maninterance-words-left">维护分队</view>
					<view class="maninterance-words-right">{{ detail.teamRowGuid }}</view>
				</view>
				<view class="maninterance-words"><view class="maninterance-words-left">维护内容</view></view>
				<textarea disabled :value="detail.result ? detail.result : '暂无内容...'" class="manage-textarea" />
			</view>
			<!-- <navigator class="maintenance-write" :url="'maintenance-manage-notes?id='+detail.id+'&category='+categoryId+'&eqId='+eqId+'&result='+detail.result+'&createTime='+detail.createTime+
				'&systemId='+systemId+'&status='+taskStatus">填写故障处理记录</navigator> -->
			<button @click="writeFault">填写故障处理记录</button>
		</view>
	</view>
</template>

<script>
import uniDrawer from '@/components/uni-drawer/uni-drawer.vue';
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import uniIcon from '@/components/uni-icon/uni-icon.vue';
export default {
	components: {
		uniDrawer,
		uniNavBar,
		uniIcon
	},
	data() {
		return {
			dic_data: [
				{
					name: '任务分类',
					data: []
				},
				{
					name: '状态',
					data: []
				},
				{
					name: '优先级别',
					data: []
				},
				{
					name: '所属系统',
					data: []
				}
			],
			detail: {
				equipmentRowGuid: '', //设备唯一标识
				category: '', //任务分类
				priorityLevel: '', //任务优先级
				teamRowGuid: '', //分队唯一标识
				status: '', //任务状态
				result: '' //维护结果
			},
			objData: [], //所有处理对象
			teamData: [], //维护队伍
			equipmentData: [], //设备集合
			optionId: '',
			systemName: '',
			categoryId: '',
			eqId: '',
			systemFlag: false,
			systemId: '',
			taskStatus: '',
			passParam: {
				id: '',
				category: '',
				eqId: '',
				result: '',
				createTime: '',
				systemId: '',
				status: ''
			} //传递的多个参数
		};
	},

	methods: {
		back() {
			uni.navigateBack({
				delta: 1
			});
		},

		async getInfo() {
			//维护队伍
			await this.$api.MaintenanceTask.ShowTeamData()
				.then(res => {
					// console.log(res)
					this.teamData = res[1].data.result;
				})
				.catch(res => {
					uni.showToast({
						title: '维护队伍获取失败',
						duration: 2000
					});
				});

			//获取处理对象
			await this.$api.MaintenanceTask.GetObjectName()
				.then(res => {
					// console.log(res)
					this.objData = res[1].data.result;
				})
				.catch(res => {
					uni.showToast({
						title: '处理对象获取失败',
						duration: 2000,
						icon: 'none'
					});
				});

			//获取设备
			let listParam = {
				parameter: '',
				operators: '',
				queryValue: '',
				pageSize: -1,
				pageIndex: -1,
				orderBy: '',
				orderByType: ''
			};
			await this.$api.MaintenanceTask.ShowEquipmentData(listParam)
				.then(res => {
					// console.log(res)
					this.equipmentData = res[1].data.result.items;
				})
				.catch(res => {
					uni.showToast({
						title: '设备获取失败',
						duration: 2000,
						icon: 'none'
					});
				});
		},

		getDetail(id) {
			let param = { id: id };
			this.$api.MaintenanceTask.DetailData(param)
				.then(res => {
					console.log(res);
					this.detail = res[1].data.result;
					this.passParam.id = this.detail.id;
					this.passParam.result = this.detail.result;
					this.passParam.createTime = this.detail.createTime;
					if (this.detail.category == '002') {
						//设备有所属系统
						this.systemFlag = true;
						this.equipmentData.forEach(ele => {
							if (ele.id == this.detail.equipmentRowGuid) {
								this.systemId = ele.systemName;
								this.passParam.systemId = ele.systemName;
								this.systemName = this.$helper.getTextByValue('所属系统', ele.systemName);
							}
						});
					}

					this.objData.forEach(ele => {
						//处理对象转换
						if (ele.ojbectId == this.detail.equipmentRowGuid) {
							this.detail.equipmentRowGuid = ele.ojbectName;
							this.eqId = ele.ojbectId;
							this.passParam.eqId = ele.ojbectId;
						}
					});

					this.getTeamName(this.detail.teamRowGuid);
					this.categoryId = this.detail.category;
					this.passParam.category = this.detail.category;
					this.detail.category = this.$helper.getTextByValue('任务分类', this.detail.category);
					this.detail.status = this.$helper.getTextByValue('状态', this.detail.status);
					this.detail.priorityLevel = this.$helper.getTextByValue('优先级别', this.detail.priorityLevel);

					if (this.detail.result == null) {
						this.detail.result = '暂无内容..';
					}
				})
				.catch(res => {
					uni.showToast({
						title: '详情获取失败',
						duration: 2000,
						icon: 'none'
					});
				});
		},
		getTeamName(id) {
			console.log('zhuayid' + id);
			this.$api.MaintenanceTask.ShowTeamData({ id: id })
				.then(res => {
					console.log(res[1].data.result);
					this.detail.teamRowGuid = res[1].data.result.teamName == undefined ? '--' : res[1].data.result.teamName;
					// this.objData.teamRowGuid = jiekou.teamName;
				})
				.catch(res => {
					//接口请求失败
					uni.showToast({
						title: '接口数据请求失败',
						duration: 2000
					});
				});
		},
		writeFault() {
			console.log(this.passParam);
			uni.navigateTo({
				url: 'maintenance-manage-notes?passParam=' + JSON.stringify(this.passParam)
			});
		}
	},
	onLoad: async function(option) {
		await this.getInfo();
		this.taskStatus = option.status;
		this.passParam.status = option.status;
		this.optionId = option.id;
		this.getDetail(this.optionId);
	},
	onShow() {},
	onReady() {}
};
</script>

<style>
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #f2f2f2;
}

.flex-item {
	font-size: 20px;
	text-align: center;
}

.uni-icon {
	padding-left: 42%;
}

.uni-navbar__header-btns {
	padding: 0;
}

.uni-navbar__header-btns:last-child {
	width: 120px;
}

.manintenance-container {
	width: 94%;
	background-color: #ffffff;
	margin: 0 auto;
	margin-top: 10px;
	border-radius: 3px;
	overflow: hidden;
	padding-bottom: 20px;
}

.maninterance-words {
	width: 94%;
	border-bottom: 1px solid #e5e5e5;
	margin: 0 auto;
	overflow: hidden;
	padding: 14px 0px;
}

.maninterance-words-left {
	font-size: 16px;
	color: #999999;
	float: left;
}

.maninterance-words-right {
	font-size: 16px;
	color: #333333;
	float: right;
}

.manage-textarea {
	font-size: 14px;
	color: #000000;
	padding-top: 10px;
}

textarea {
	border: 1px solid #e5e5e5;
	width: 94%;
	margin: 0 auto;
	border-radius: 3px;
	border-top: none;
}

.maintenance-write {
	width: 94%;
	height: 52px;
	margin: 0 auto;
	margin-top: 15px;
	font-size: 16px;
	color: #ffffff;
	background-color: #458cd0;
	border-radius: 3px;
	text-align: center;
	line-height: 52px;
}

.button-hover {
	color: #fff;
	background-color: #169bd5;
	font-size: 16px;
	height: 52px;
	line-height: 52px;
	width: 94%;
	border-radius: 3px;
	margin-top: 15px;
}

button {
	color: #fff;
	background-color: #169bd5;
	font-size: 16px;
	height: 52px;
	line-height: 52px;
	width: 94%;
	border-radius: 3px;
	margin-top: 15px;
}
</style>
